#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Copyright (c) 2016-2018, Niklas Hauser
# Copyright (c) 2017, Fabian Greif
#
# This file is part of the modm project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# -----------------------------------------------------------------------------

def init(module):
    module.name = ":board:disco-f746ng"
    module.description = """\
# STM32F7DISCOVERY

[Discovery kit for STM32F746](https://www.st.com/en/evaluation-tools/32f746gdiscovery.html)

## TinyUSB

This board has two USB ports: one with Full Speed support and another with true
High Speed support. By default, TinyUSB runs the device classes on the FS port,
however, you can reassign it to HS via this option:

```xml
<options>
  <option name="modm:tinyusb:config">device.cdc,device.msc</option>
  <option name="modm:tinyusb:device:port">hs</option>
</options>
```

Remember to initialize the HS instead of the FS port via the BSP:

```cpp
Board::initialize();
Board::initializeUsbHs();
```

Note that can use TinyUSB with both the device and host classes at the same time
if you assign them to different ports:

```xml
```xml
<options>
  <option name="modm:tinyusb:config">device.cdc,device.msc</option>
  <option name="modm:tinyusb:device:port">fs</option>
  <option name="modm:tinyusb:host:port">hs</option>
</options>
```

You must initialize both ports via the BSP:

```cpp
Board::initialize();
Board::initializeUsbFs();
Board::initializeUsbHs();
```
"""

def prepare(module, options):
    if not options[":target"].partname.startswith("stm32f746ngh"):
        return False

    module.depends(
        ":architecture:clock",
        ":debug",
        ":platform:clock",
        ":platform:core",
        ":platform:gpio",
        ":platform:uart:1",
        ":platform:usb:fs",
        ":platform:usb:hs")
    return True

def build(env):
    env.outbasepath = "modm/src/modm/board"
    env.substitutions = {
        "with_logger": True,
        "with_assert": env.has_module(":architecture:assert")
    }
    env.template("../board.cpp.in", "board.cpp")
    env.copy('.')
    env.collect(":build:openocd.source", "board/stm32f7discovery.cfg")
